<?php 

Class indexController extends appController
{
	
	public function index()
	{
		$this->assign_global();
		$this->display("index.html");
	}
	
	public function act_upload()
	{
		$path='/menu/';
		$file=current($_FILES);
		$arr = array();
		foreach($file as $k => $v)
		{
			$arr[$k] = $v[0];
		}
		$file = $arr;
		$result=array('error'=>0,'url'=>$file['name']);
		$thumb_url=Model('image')->upload_image($file, $path.date('Ym'));
		$result['url']=$thumb_url;
	
		$result['message']='';
		print_r(json_encode($result));
		exit();
	}
	public function checkcode()
	{
		$result=array('error'=>1,'content'=>'抱歉，本数据库没有此记录');
		$code1=hy_check(strtoupper($_POST['code1']),'u');
		$code2=hy_check(strtoupper($_POST['code2']),'u');
		$code3=hy_check(strtoupper($_POST['code3']),'u');
		$code4=hy_check(strtoupper($_POST['code4']),'u');
		if($code1=='#@_error'||$code2=='#@_error'||$code3=='#@_error'||$code4=='#@_error')
		{
			print_r(json_encode($result));
			exit;
		}
		$code=$code1.$code2.$code3.$code4;
		$res=Model('index')->db_count(array('table'=>'security_code','code'=>$code));
		if($res==1)
		{
			$result['error']=0;
			$result['content']='该防伪码有效';
		}
	print_r(json_encode($result));
	exit;
		
	}
	public function code()
	{
		$cache_id = DEFAULT_LANG;
		
		$cache_id = sprintf('%X', crc32($cache_id));
		if (!$this->is_cached('code.html',$cache_id))
		{
			$app=Model('app');
		$this->assign_global();
		$cat=$app->getTopClass('security');
		$this->assign('top',$cat);
		$this->assign('code','security');
		
		}
		$this->display('code.html',$cache_id);
	}
	private function unique($length = 10) {
	
		$string = uniqid(md5(rand(0, time())));
	
		if ($length >= strlen($string)) {
	
			return $string;
	
		}
		$strlen=strlen($string);
		$dif=$strlen-$length+1;
		$rand=rand(0, $dif);
		return substr($string, $rand, $length);
	
	}
	private function id_arr($length=10000,$array=array())
	{
		$arr=array();
		for($i=0;$i<$length;$i++)
		{
		$temp[]=strtoupper($this->unique(16));
		}
		$temp = array_unique($temp);
		$num=count($temp);
		if($num==$length)
		{
			if($array[0]!='')
			{
				$temp=array_merge($array,$temp);
			}
		    return $temp;
	     }
	    else
		{
			$dif=$length-$num;
		   return $this->id_arr($dif,$temp);
		}
	}
	function guid() {
		@set_time_limit(0) ;
	//$temp=$this->id_arr();	
	foreach($temp as $k=>$v)
	{
		$arr[$k]['code']=$v;
		$arr[$k]['createtime']=$_SERVER['REQUEST_TIME'];
	}
	
	//Model('index')->insert($arr,'security_code');
	}
	public function suggestion()
	{$cache_id = DEFAULT_LANG;
		
		$cache_id = sprintf('%X', crc32($cache_id));
		//首页轮播
		if (!$this->is_cached('suggest.html',$cache_id))
		{
			$app=Model('app');
		$this->assign_global();
		$cat=$app->getTopClass('suggestion');
		$this->assign('top',$cat);
		$this->assign('code','suggestion');
		}
		$this->display('suggest.html',$cache_id);
	}
}
?>